<template>
  <el-dialog
    :title="title"
    :visible.sync="innerVisible"
    width="600px"
    @close="handleCancel"
  >
    <el-form
      :model="form"
      :rules="rules"
      ref="formRef"
      label-width="120px"
    >
      <el-form-item label="项目名称" v-if="projectName">
        <el-input
          v-model="projectName"
          type="textarea"
          disabled
        />
      </el-form-item>
      <el-form-item label="属性">
        <!-- <el-input
          v-model="form.stage"
          placeholder="请输入"
        /> -->
        <el-select
          placeholder="属性"
          v-model="form.property"
          :disabled="editIndex > 0"
          clearable
        >
          <el-option
            v-for="item in propertyOptions"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="当前项目阶段">
        <!-- <el-input
          v-model="form.stage"
          placeholder="请输入"
        /> -->
        <el-select
          placeholder="当前项目阶段"
          v-model="form.stage"
          :disabled="editIndex > 0"
          clearable
        >
          <el-option
            v-for="item in projectStageOptions"
            :key="item"
            :label="item"
            :value="item"
          >
          </el-option>
        </el-select>
      </el-form-item>

      <el-form-item label="最新进展">
        <el-input
          v-model="form.newestProcess"
          placeholder="请输入"
          type="textarea"
        />
      </el-form-item>

      <el-form-item label="是否存在困难">
        <el-radio-group v-model="form.problemFlag">
          <el-radio label="是"></el-radio>
          <el-radio label="否"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="存在问题及原因">
        <el-input
          v-model="form.problemContent"
          placeholder="请输入"
          type="textarea"
        />
      </el-form-item>

      <el-form-item label="工作建议及举措">
        <el-input
          v-model="form.solveAdvice"
          placeholder="请输入"
          type="textarea"
        />
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleConfirm"
        >确定</el-button
      >
    </div>
  </el-dialog>
</template>

<script>
import dayjs from 'dayjs'
import {
  projectStageOptions,
  propertyOptions
} from '@/utils/project/data'

export default {
  name: 'ProgressDialog',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '填写信息'
    },
    currentData: {
      type: Object
    },
    currentInfo: {
      type: Object
    },
    editIndex: {
      type: Number
    },
    projectName: {
      type: String
    }
  },
  data() {
    return {
      form: {
        createTime: '',
        property: '',
        stage: '',
        newestProcess: '',
        problemFlag: '是',
        problemContent: '',
        solveAdvice: ''
      },
      rules: {},
      innerVisible: false
    }
  },
  computed: {
    projectStageOptions() {
      return projectStageOptions
    },
    propertyOptions() {
      return propertyOptions
    }
  },
  watch: {
    visible(val) {
      this.innerVisible = val
    },
    innerVisible(val) {
      this.$emit('update:visible', val)
    },
    currentData(val) {
      this.form = val
    },
    currentInfo(val) {
      this.form.property = val.property || ''
      this.form.stage = val.stage || ''
    }
  },
  methods: {
    handleCancel() {
      this.$emit('update:visible', false)
      this.form = {
        createTime: '',
        property: '',
        stage: null,
        newestProcess: '',
        problemFlag: '是',
        problemContent: '',
        solveAdvice: ''
      }
    },
    handleConfirm() {
      this.$refs.formRef.validate((valid) => {
        if (valid) {
          const date = new Date()
          this.form.createTime = dayjs(date).format(
            'YYYY-MM-DD hh:mm:ss'
          )
          this.$emit('confirm', this.form)
          this.handleCancel()
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import '~@/assets/css/dialog.scss';
::v-deep .el-input__inner {
  width: 320px !important;
}
</style>
